package com.yuexin.project.mobile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;
import com.yuexin.common.utils.StringUtils;
import com.yuexin.framework.web.controller.BaseController;
import com.yuexin.project.finance.bill.domain.Bill;
import com.yuexin.project.finance.bill.service.IBillService;
import com.yuexin.project.system.user.domain.User;
import com.yuexin.project.system.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Ahanu
 */
@Api("手机端余额管理")
@RestController
@RequestMapping("/meals/mobile")
public class BillForMobileAPIController extends BaseController {

    @Autowired
    private IBillService billService;
    @Autowired
    private IUserService userService;

    @GetMapping("/getBills")
    @ApiOperation("获取账单列表")
    public Result selectNoticeByUserName(String json) {
        JSONObject jobj = JSON.parseObject(json);
        JSONObject data = (JSONObject) jobj.get("data");
        JSONObject token = data.getJSONObject("token");
        User user = userService.selectUserByLoginName(token.getString("userName"));
        user.getMoney();
        Map<String, Object> result = Maps.newHashMap();
        result.put("money", user.getMoney());
        Bill bill = new Bill();
        bill.setBillType(StringUtils.isNotBlank(data.getString("billType")) ? data.getString("billType") : null);
        bill.setCompanyId(token.getString("companyId"));
        bill.setUserName(token.getString("userName"));
        PageHelper.startPage(data.getInteger("pageNum"), data.getInteger("pageSize"), "create_time desc");
        startPage();
        result.put("bill", getDataTable(billService.selectBillList(bill)));
        return new Result(ResultCode.SUCCESS, result);
    }

}
